package base;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum ContentTypeEnum {

    AUDIO(1, "音频", "audio"),
    VIDEO(2, "视频", "video"),
    PHOTOS(3, "组图", "picture"),
    ARTICLE(4, "文章", "article"),
    TOPIC(5, "专题", "topic"),

    ;

    private final Integer code;
    private final String desc;
    private final String title;

    ContentTypeEnum(Integer code, String desc, String title) {
        this.code = code;
        this.desc = desc;
        this.title = title;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public String getTitle() {
        return title;
    }

    private static final Map<Integer, ContentTypeEnum> ENUM_MAP;

    static {
        ENUM_MAP = Arrays.stream(ContentTypeEnum.values())
                .collect(Collectors.toMap(ContentTypeEnum::getCode, Function.identity(), (o, n) -> n));
        System.out.println(ENUM_MAP);
    }

    /**
     * 根据code获取枚举
     *
     * @param code
     * @return
     */
    public static ContentTypeEnum getByCode(Integer code) {
        return ENUM_MAP.get(code);
    }

    public static void main(String[] args) {
        System.out.println(ContentTypeEnum.ARTICLE.getCode());
        System.out.println(ContentTypeEnum.ARTICLE.getDesc());
        System.out.println(ContentTypeEnum.ARTICLE.getTitle());
    }

}
